package com.powergisol.gis.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.powergisol.gis.dto.ExcelRectangularPillarModelDTO;
import com.powergisol.gis.entity.TabCoordinateSystem;
import com.powergisol.gis.entity.TabGriderHighwidth;
import com.powergisol.gis.entity.TabGriderSteady;
import com.powergisol.gis.util.XyChangeUtil;
import com.powergisol.gis.vo.ExcelInFailedDataVo;
import com.powergisol.gis.vo.TabGriderVO;
import com.powergisol.gis.vo.TaskResultVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;

import java.math.BigDecimal;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.regex.Pattern;

/**
 * @author : laishihao
 * @date : 2020/11/14
 * description :
 */
public class GirderExcelModelListener extends AnalysisEventListener {
    private final static Pattern NUMBER_PATTERN = Pattern.compile("([+\\-]?[0-9]+[.]?[\\d]*)");

    private TabGriderVO vo;

    //坐标系bean
    TabCoordinateSystem system;

    CacheManager cacheManager;

    String excelName;
    //字段值所在列数
    private Integer valueColumn;

    private ExcelRectangularPillarModelDTO rectangularPillarModelDTO;
    private BigDecimal lon;
    private BigDecimal lat;
    private BigDecimal altitude;

    Map<String, String> map1 = new HashMap<>();
    Map<String, String> map2 = new HashMap<>();

    public GirderExcelModelListener() {

    }

    public GirderExcelModelListener(TabGriderVO vo, TabCoordinateSystem system,
                                    CacheManager cacheManager, BigDecimal lon, BigDecimal lat, BigDecimal altitude,
                                    ExcelRectangularPillarModelDTO rectangularPillarModelDTO) {

        this.vo = vo;
        this.system = system;
        this.cacheManager = cacheManager;
        this.lon = lon;
        this.lat = lat;
        this.altitude = altitude;
        this.rectangularPillarModelDTO = rectangularPillarModelDTO;
    }

    @Override
    public void invoke(Object o, AnalysisContext context) {
        ArrayList data = (ArrayList) o;
        try {
            if (data.isEmpty()) {
                return;
            }
            int j = 0;
            int dataSize = data.size();
            for (int i = 0; i < dataSize; i++) {
                if (j == 1) {
                    return;
                }
                String str = String.valueOf(data.get(i));
                if (StringUtils.isBlank(str)) continue;

                //如果列数存在
                if (null == valueColumn && str.equals("字段值")) {
                    valueColumn = i;
                }

                switch (str) {
                    case "Hcdm01":
                        vo.setHcdm01(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "Hcdm02":
                        vo.setHcdm02(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "Hcdm03":
                        vo.setHcdm03(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "Hcdm04":
                        vo.setHcdm04(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "Hcdm05":
                        vo.setHcdm05(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "Hcdm06":
                        vo.setHcdm06(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL21":
                        if (NUMBER_PATTERN.matcher(String.valueOf(data.get(valueColumn))).matches()) {
                            vo.setKL21(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        }
                        j++;
                        break;
                    case "KL22":
                        if (NUMBER_PATTERN.matcher(String.valueOf(data.get(valueColumn))).matches()) {
                            vo.setKL22(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        }
                        j++;
                        break;
                    case "KL23":
                        vo.setKL23(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        j++;
                        break;
                    case "KL24":
                        vo.setKL24(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        j++;
                        break;
                    case "KL25":
                        vo.setKL25(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        j++;
                        break;
                    case "KL26":
                        vo.setKL26(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : BigDecimal.valueOf(Double.parseDouble(String.valueOf(data.get(valueColumn)))));
                        j++;
                        break;
                    case "KL（28，1）":
                        vo.setKL28(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        map2.put("KL281", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，1）":
                        vo.setKL29(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        map2.put("KL291", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，2）":
                        map2.put("KL282", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，2）":
                        map2.put("KL292", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，3）":
                        map2.put("KL283", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，3）":
                        map2.put("KL293", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，4）":
                        map2.put("KL284", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，4）":
                        map2.put("KL294", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，5）":
                        map2.put("KL285", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，5）":
                        map2.put("KL295", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，6）":
                        map2.put("KL286", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，6）":
                        map2.put("KL296", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，7）":
                        map2.put("KL287", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，7）":
                        map2.put("KL297", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，8）":
                        map2.put("KL288", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，8）":
                        map2.put("KL298", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（28，9）":
                        map2.put("KL289", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL（29，9）":
                        map2.put("KL299", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "KL30":
                        vo.setKL30(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL31":
                        vo.setKL31(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL32":
                        vo.setKL32(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL33":
                        vo.setKL33(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL34":
                        vo.setKL34(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "KL50":
                        vo.setKL50(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : Integer.parseInt(String.valueOf(data.get(valueColumn))));
                        j++;
                        break;
                    case "LD（1，1）":
                        vo.setLD1(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "LD（2，1）":
                        vo.setLD2(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "LD（3，1）":
                        vo.setLD3(valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，1）":
                        map1.put("zz11", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，1）":
                        map1.put("zz21", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，1）":
                        map1.put("zz31", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，1）":
                        map1.put("zz41", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，1）":
                        map1.put("zz51", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，2）":
                        map1.put("zz12", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，2）":
                        map1.put("zz22", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，2）":
                        map1.put("zz32", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，2）":
                        map1.put("zz42", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，2）":
                        map1.put("zz52", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，3）":
                        map1.put("zz13", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，3）":
                        map1.put("zz23", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，3）":
                        map1.put("zz33", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，3）":
                        map1.put("zz43", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，3）":
                        map1.put("zz53", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，4）":
                        map1.put("zz14", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，4）":
                        map1.put("zz24", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，4）":
                        map1.put("zz34", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，4）":
                        map1.put("zz44", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，4）":
                        map1.put("zz54", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，5）":
                        map1.put("zz15", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，5）":
                        map1.put("zz25", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，5）":
                        map1.put("zz35", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，5）":
                        map1.put("zz45", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，5）":
                        map1.put("zz55", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，6）":
                        map1.put("zz16", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，6）":
                        map1.put("zz26", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，6）":
                        map1.put("zz36", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，6）":
                        map1.put("zz46", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，6）":
                        map1.put("zz56", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，7）":
                        map1.put("zz17", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，7）":
                        map1.put("zz27", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，7）":
                        map1.put("zz37", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，7）":
                        map1.put("zz47", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，7）":
                        map1.put("zz57", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    case "ZZ（1，8）":
                        map1.put("zz18", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，8）":
                        map1.put("zz28", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，8）":
                        map1.put("zz38", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，8）":
                        map1.put("zz48", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，8）":
                        map1.put("zz58", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（1，9）":
                        map1.put("zz19", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（2，9）":
                        map1.put("zz29", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（3，9）":
                        map1.put("zz39", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（4，9）":
                        map1.put("zz49", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;
                    case "ZZ（5，9）":
                        map1.put("zz59", valueColumn >= dataSize ? null : null == data.get(valueColumn) ? null : String.valueOf(data.get(valueColumn)));
                        j++;
                        break;

                    default:
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        saveDate();
    }

    private synchronized void saveDate() {
        vo.setHcdm02(vo.getSheetName());
        //梁基础数据保存
        vo.setOKL21(vo.getKL21());
        vo.setOKL22(vo.getKL22());
        vo.setOKL23(vo.getKL23());
        vo.setOKL24(vo.getKL24());
        vo.setOKL25(vo.getKL25());
        vo.setOKL26(vo.getKL26());

        //转换单位 (mm 转 m )
        BigDecimal KL21 = lon.add(mmTom(vo.getKL21()));
        BigDecimal KL22 = lat.add(mmTom(vo.getKL22()));
        BigDecimal KL23 = altitude.add(mmTom(vo.getKL23()));
        vo.setKL23(KL23);

        if (!NUMBER_PATTERN.matcher(String.valueOf(KL21)).matches()) {
            dealFail("坐标Xl需为数字");
            return;
        }
        if (!NUMBER_PATTERN.matcher(String.valueOf(KL22)).matches()) {
            dealFail("坐标Yw需为数字");
            return;
        }
        BigDecimal tempKl21;
        BigDecimal tempKl22;
//        if (1 == vo.getIsChange()) {
//            tempKl21 = XyChangeUtil.changex(KL21, KL22);//经度
//            tempKl22 = XyChangeUtil.changey(KL21, KL22);//纬度
//        } else {
//            tempKl21 = vo.getKL21();//经度
//            tempKl22 = vo.getKL22();//纬度
//        }

//        if (tempKl21.compareTo(new BigDecimal("180")) > 0 || tempKl21.compareTo(new BigDecimal("-180")) < 0 ||
//                tempKl22.compareTo(new BigDecimal("90")) > 0 || tempKl22.compareTo(new BigDecimal("-90")) < 0) {
//            dealFail("坐标Xl或坐标Yw不在范围内");
//            return;
//        }
        vo.setKL21(KL21);
        vo.setKL22(KL22);
        vo.setKL25(mmTom(vo.getKL25()));
        vo.setKL26(mmTom(vo.getKL26()));

        //梁基础信息 持久化
        rectangularPillarModelDTO.getGridersList1().add(vo);

        //支座保存 梁宽梁高
        LinkedBlockingDeque<TabGriderSteady> griderSteadyList = new LinkedBlockingDeque<>();
        LinkedBlockingDeque<TabGriderHighwidth> griderHighwidthList = new LinkedBlockingDeque<>();
        //累计梁中净距
        BigDecimal distance = new BigDecimal(0);
        //累计支座宽
        BigDecimal steadyWidth = new BigDecimal(0);

        for (int i = 0; i < vo.getKL50() - 1; i++) {
            //创建StringBuffer
            StringBuffer s6 = new StringBuffer();
            s6.append("KL28");
            StringBuffer s7 = new StringBuffer();
            s7.append("KL29");
            StringBuffer s1 = new StringBuffer();
            s1.append("zz1");
            StringBuffer s2 = new StringBuffer();
            s2.append("zz2");
            StringBuffer s3 = new StringBuffer();
            s3.append("zz3");
            StringBuffer s4 = new StringBuffer();
            s4.append("zz4");
            StringBuffer s5 = new StringBuffer();
            s5.append("zz5");
            //拼接字符串
            s1.append(i + 1);
            s2.append(i + 1);
            s3.append(i + 1);
            s4.append(i + 1);
            s5.append(i + 1);
            s6.append(i + 1);
            s7.append(i + 1);
            //连续梁高与连续梁宽
            TabGriderHighwidth highwidth = new TabGriderHighwidth();
            highwidth.setUuid(vo.getUuid());
            highwidth.setHcdm02(vo.getHcdm02());
            highwidth.setSteadyNum(i + 1);
            if (map2.get(s6.toString()) != null) {
                highwidth.setKL28(map2.get(s6.toString()));
            }else {
                highwidth.setKL28(vo.getKL28());
            }
            if (map2.get(s7.toString()) != null) {
                highwidth.setKL29(map2.get(s7.toString()));
            } else {
                highwidth.setKL29(vo.getKL29());
            }
            //存入集合
            griderHighwidthList.offer(highwidth);

            //梁 支座信息保存
            TabGriderSteady griderSteady = new TabGriderSteady();
            griderSteady.setUuid(vo.getUuid());
            griderSteady.setHcdm02(vo.getHcdm02());
            griderSteady.setSteadyNum(i + 1);
            String s = String.valueOf(vo.getKL24());
            switch (s) {
                case "0.0":
                    //支座存储连续相加的 经度
                    if (map1.get(s3.toString()) != null) {
                        //首先赋值支座开始经度 （但赋值在计算本次支座宽和梁中净距之前。 相加之前的 累计梁中净距 + 累记支座宽）
                        //支座开始经度为 (基准值 + 相对值) + 累计梁中净距 + 累记支座宽
                        griderSteady.setLon(KL21.add(distance).add(steadyWidth));


                        //支座宽
                        BigDecimal newSteadyWidth = mmTom(steadyWidth.add(BigDecimal.valueOf(Double.valueOf(map1.get(s1.toString())))));
                        //依次增加支座宽 累计支座宽
                        steadyWidth = steadyWidth.add(newSteadyWidth);

                        //支座末尾经度  （但赋值仅在计算本次梁中净距之前。 相加之前的累计梁中净距 +本次累计支座宽）
                        //支座末尾经度为 (基准值 + 相对值) + 累计支座宽 + 累计梁中净距
                        griderSteady.setEndLon(KL21.add(distance).add(steadyWidth));


                        //最后才计算中净距
                        BigDecimal mmTom = mmTom(distance.add(BigDecimal.valueOf(Double.valueOf(map1.get(s3.toString())))));
                        //累计计算 梁中净距
                        distance = distance.add(mmTom);
                        //下个支座开始经度 （相加本次累计的 梁中净距 + 支座宽）
                        //赋值下一个支座开始经度 (基准值 + 相对值) + 累计支座宽 + 累计梁中净距
                        griderSteady.setNextStartLon(KL21.add(distance).add(steadyWidth));

                        griderSteady.setLat(KL22);
                        griderSteady.setEndLat(KL22);
                        griderSteady.setNextStartLat(KL22);

                    }
                    break;
                case "90.0":
                    if (map1.get(s3.toString()) != null) {
                        //首先赋值支座开始纬度 （但赋值在计算本次支座宽和梁中净距之前。 相加之前的 累计梁中净距 + 累记支座宽）
                        //支座开始经度为 (基准值 + 相对值) + 累计梁中净距 + 累记支座宽
                        griderSteady.setLat(KL22.add(distance).add(steadyWidth));


                        //支座宽
                        BigDecimal newSteadyWidth = mmTom(steadyWidth.add(BigDecimal.valueOf(Double.valueOf(map1.get(s1.toString())))));
                        //依次增加支座宽 累计支座宽
                        steadyWidth = steadyWidth.add(newSteadyWidth);

                        //支座末尾纬度  （但赋值仅在计算本次梁中净距之前。 相加之前的累计梁中净距 +本次累计支座宽）
                        //支座末尾纬度为 (基准值 + 相对值) + 累计支座宽 + 累计梁中净距
                        griderSteady.setEndLat(KL22.add(distance).add(steadyWidth));


                        //最后才计算中净距
                        BigDecimal mmTom = mmTom(distance.add(BigDecimal.valueOf(Double.valueOf(map1.get(s3.toString())))));
                        //累计计算 梁中净距
                        distance = distance.add(mmTom);
                        //下个支座开始纬度 （相加本次累计的 梁中净距 + 支座宽）
                        //赋值下一个支座开始纬度 (基准值 + 相对值) + 累计支座宽 + 累计梁中净距
                        griderSteady.setNextStartLat(KL22.add(distance).add(steadyWidth));

                        griderSteady.setLon(KL21);
                        griderSteady.setEndLon(KL21);
                        griderSteady.setNextStartLon(KL21);
                    }
                    break;
                default:
                    break;
            }


            griderSteady.setZz1(map1.get(s1.toString()));
            griderSteady.setZz2(map1.get(s2.toString()));
            griderSteady.setZz3(map1.get(s3.toString()));
            griderSteady.setZz4(map1.get(s4.toString()));
            griderSteady.setZz5(map1.get(s5.toString()));
            //存入集合
            griderSteadyList.offer(griderSteady);
        }

        //梁 支座信息持久化
        rectangularPillarModelDTO.getGriderSteadyList1().add(griderSteadyList);
        //连续梁高与连续梁宽 持久化
        rectangularPillarModelDTO.getGriderHighwidthList1().add(griderHighwidthList);

    }


    //转换单位 (mm 转 m （毫米 转 米）)
    private BigDecimal mmTom(BigDecimal mm) {
        if (mm != null) {
            return mm.divide(new BigDecimal("1000"), 10, BigDecimal.ROUND_DOWN);
        }
        return null;
    }

    private void dealFail(String msg) {
        List<ExcelInFailedDataVo> listFailed = new ArrayList<>();
        ExcelInFailedDataVo failedDataVo = new ExcelInFailedDataVo();
        failedDataVo.setReason(msg);
        failedDataVo.setRowIndex(excelName);
        listFailed.add(failedDataVo);
        Cache cache = cacheManager.getCache("cache-data");
        TaskResultVo resultVo = new TaskResultVo();
        resultVo.setListFailed(listFailed);
        cache.put(excelName + "sb", resultVo);
    }

}
